{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Regularization path of L1- Logistic Regression\n",
    "# L1-逻辑回归的正则化路径\n",
    "\n",
    "\n",
    "Train l1-penalized logistic regression models on a binary classification problem derived from the Iris dataset.\n",
    "\n",
    "The models are ordered from strongest regularized to least regularized. The 4 coefficients of the models are collected and plotted as a \"regularization path\": on the left-hand side of the figure (strong regularizers), all the coefficients are exactly 0. When regularization gets progressively looser, coefficients can get non-zero values one after the other.\n",
    "\n",
    "Here we choose the SAGA solver because it can efficiently optimize for the Logistic Regression loss with a non-smooth, sparsity inducing l1 penalty.\n",
    "\n",
    "Also note that we set a low value for the tolerance to make sure that the model as converged before collecting the coefficients.\n",
    "\n",
    "We also use warm_start=True which means that the coefficients of the models are reused to initialize the next model fit to speed-up the computation of the full-path.\n",
    "\n",
    "采用IRIS鸢尾花数据集，利用L1惩罚的Logistic回归模型进行训练，该问题为二分类问题。\n",
    "\n",
    "得到的训练模型按照由强到弱正则化排序，通过模型的4个特征值对应的系数绘制“正则化路径”图：在图的左侧（强正则化器），所有特征系数都是0。但当正则化逐渐变松时（即C值变大时），特征系数得到非零值。\n",
    "\n",
    "在这里，本例选择SAGA求解方法，是因为它可以有效地优化Logistic回归损失，并且可以使得L1惩罚函数具有非平滑、稀疏性。\n",
    "\n",
    "还要注意，本例为公差设置了一个较低的值，以确保在得到模型系数之前模型收敛。\n",
    "\n",
    "使用warm_start=true，为了使模型的参数能够被重用，并初始化下一个模型，以加快整个路径的计算速度。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automatically created module for IPython interactive environment\n"
     ]
    }
   ],
   "source": [
    "print(__doc__)\n",
    "\n",
    "# Author: Alexandre Gramfort <alexandre.gramfort@inria.fr>\n",
    "# License: BSD 3 clause\n",
    "\n",
    "from time import time\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from sklearn import linear_model\n",
    "from sklearn import datasets\n",
    "from sklearn.svm import l1_min_c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载鸢尾花数据集\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X = X[y != 2]\n",
    "y = y[y != 2]\n",
    "\n",
    "# Normalize X to speed-up convergence\n",
    "# 为了加速收敛，对特征集X进行归一化\n",
    "X /= X.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.00071480e-01, 2.93073795e-01, 8.58308976e-01, 2.51368192e+00,\n",
       "       7.36168089e+00, 2.15597467e+01, 6.31408350e+01, 1.84917063e+02,\n",
       "       5.41556353e+02, 1.58602607e+03, 4.64490662e+03, 1.36032805e+04,\n",
       "       3.98391736e+04, 1.16674779e+05, 3.41698958e+05, 1.00071480e+06])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# #############################################################################\n",
    "# Demo path functions\n",
    "# 计算一个C的下限值，然后放大到一个区间内\n",
    "# logspac用于创建等比数列：从0到1e+07，元素个数为16个\n",
    "cs = l1_min_c(X, y, loss='log') * np.logspace(0, 7, 16)\n",
    "cs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Computing regularization path ...\n",
      "This took 5.671s\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEWCAYAAAB42tAoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGx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/gKNVG2C2iCzD+QHxpapGfbfTGNEKmCsiS3EGI52uqp97HFMwNwFvu/8W+gATInUgG8LDGGNMUFajMMYYE5QlCmOMMUFZojDGGBOUJQpjjDFBWaIwxhgTlCUKY0IkIgcq3yro/lNFpIv7uqGIvCIiv7ijwH4jIseLSJL7us7cDGuinyUKY2qAiBwJxKvqWnfRqzgDJ3ZT1SOBK4AW7qCPXwEjPAnUmAAsURhTReJ4wh0r7AcRGeEujxORF90awqci8pmInOfudgnwL3e73wHHA/epqh/AHRl4urvtx+72xkQFq94aU3V/wrkTtjfQAlggIt/g3OXdGTgaaIlzF/3f3X36A++4r48Elqiqr4LyfwSOjUjkxlSD1SiMqboBwDvuKK7bgH/jnNgHAP9UVb87Fs/sEvu0wRkWulJuAikoHnfIGK9ZojCm6gIN+x5sOUAuzgiqAD8BvUUk2P+/ekBeNWIzJuwsURhTdd8AI9wJhNJwZhr7HpgL/I/bVtEKOKXEPiuArgCq+guQAYx3R69FRLoVz40iIs2B7apaWFMfyJhgLFEYU3UfAcuApcDXwGj3UtMHOPME/Ai8gjNT3l53n+mUThxXA62Bn0XkB+BvHJxj5FTgs8h+BGNCZ6PHGhNGItJQVQ+4tYLvcWZM2+rOHTHbfV9RI3ZxGR8CY6J8HndTh1ivJ2PC61N3YqEk4EG3poGq5orIAzhznW+oaGd3YqqPLUmYaGI1CmOMMUFZG4UxxpigLFEYY4wJyhKFMcaYoCxRGGOMCcoShTHGmKD+H1Q/1UzAACblAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(\"Computing regularization path ...\")\n",
    "start = time()\n",
    "# 创建Logistic模型\n",
    "clf = linear_model.LogisticRegression(penalty='l1', solver='saga',\n",
    "                                      tol=1e-6, max_iter=int(1e6),\n",
    "                                      warm_start=True)\n",
    "coefs_ = []\n",
    "for c in cs:\n",
    "    clf.set_params(C=c)\n",
    "    clf.fit(X, y)\n",
    "    # 将模型得到的特征系数转变为一维向量并进行存储\n",
    "    coefs_.append(clf.coef_.ravel().copy())\n",
    "print(\"This took %0.3fs\" % (time() - start))\n",
    "\n",
    "coefs_ = np.array(coefs_)\n",
    "# 绘制折线图展示\n",
    "plt.plot(np.log10(cs), coefs_, marker='o')\n",
    "ymin, ymax = plt.ylim()\n",
    "plt.xlabel('log(C)')\n",
    "plt.ylabel('Coefficients')\n",
    "plt.title('Logistic Regression Path')\n",
    "plt.axis('tight')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
